home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / bin / sh-versions / showaudio.z / showaudio
Encoding:
Text File  |  1997-01-22  |  7.5 KB  |  322 lines

  1. :
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13.  
  14. # Conversion from C shell to Bourne shell by Z-Code Software Corp.
  15. # Conversion Copyright (c) 1992 Z-Code Software Corp.
  16. # Permission to use, copy, modify, and distribute this material
  17. # for any purpose and without fee is hereby granted, provided
  18. # that the above copyright notice and this permission notice
  19. # appear in all copies, and that the name of Z-Code Software not
  20. # be used in advertising or publicity pertaining to this
  21. # material without the specific, prior written permission
  22. # of an authorized representative of Z-Code.  Z-CODE SOFTWARE
  23. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  24. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  25. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  26.  
  27. # Brought into line with metamail 2.7 beta release Csh version
  28. # Added sox support
  29. #    Dave Shield    February 1994
  30.  
  31. if test -z "${METAMAIL_TMPDIR:-}"
  32. then
  33.         METAMAIL_TMPDIR=/tmp
  34. fi
  35.  
  36. thishost=`hostname`
  37.  
  38. AUDIOBINDIR=/u/andrew/phone-sau/bin
  39. AUDIOPHONEHOST=greenbush
  40. AUDIOPHONEHOSTLONG=greenbush.bellcore.com
  41. AUDIOLOGMAIL=greenbush.bellcore.com
  42. ORG=Bellcore
  43. STDINPUT=0
  44.  
  45. if test -x /usr/bin/remsh
  46. then
  47.             # Probably a System V based system
  48.             #  "rsh" is likely to be "restricted shell"
  49.     RSH=remsh
  50. else
  51.     RSH=rsh
  52. fi
  53. # SOX=/usr/remote/bin9/sox
  54.  
  55. if test "$1" = "-p"
  56. then
  57.     AUDIOPHONE=$2
  58.     shift
  59.     shift
  60. fi
  61.  
  62. if test "$1" = "-s"
  63. then
  64.     AUDIOSPEAKERFORCE=1
  65.     shift
  66. fi
  67.  
  68. playphone=0
  69. if test ! -z "${AUDIOPHONE:-}" -o ! -z "${AUDIOPHONEFORCE:-}"
  70. then
  71.     playphone=1
  72. fi
  73.  
  74. if test $playphone -eq 0
  75. then
  76.     if test ! -d "$AUDIOBINDIR"
  77.     then
  78.         AUDIOSPEAKERFORCE=1
  79.     fi
  80.  
  81.     if test "$1" = "-"
  82.     then
  83.         STDINPUT=1
  84.         shift
  85.     fi
  86.     if test $# -eq 0
  87.     then
  88.         STDINPUT=1
  89.     fi
  90.  
  91.     if test $STDINPUT -eq 0 -a -z "${AUDIOSPEAKERFORCE:-}" -a -z "${AUDIOPHONEFORCE:-}"
  92.     then
  93.         if test ! -z "${MM_NOTTTY:-}"
  94.         then
  95.             if test $MM_NOTTTY -eq 1
  96.             then
  97.                 MM_NOTTTY=0; export MM_NOTTTY
  98.                 xterm -e showaudio "$@"
  99.                 exit 0
  100.             fi
  101.         fi
  102.         looping=1
  103.         while test $looping -eq 1
  104.         do
  105.             echo This program can display audio on the speakers of some workstations, 
  106.             echo "or (at some sites) it can call you on the telephone.  Please choose one:"
  107.             echo ""
  108.             echo "1 -- Use the computer's speaker"
  109.             echo "2 -- Call me on the telephone"
  110.             echo ""
  111.             echo-n "Which do you prefer (1 or 2)? [1] "
  112.             read ans
  113.             if test "$ans" -eq 2
  114.             then
  115.             echo "OK, we'll use the telephone..."
  116.             AUDIOPHONEFORCE=1
  117.             echo "In the future, you can avoid this question by setting the environment variable"
  118.             echo "AUDIOPHONEFORCE to 1"
  119.             playphone=1
  120.             looping=0
  121.             elif test "$ans" -eq 1
  122.             then
  123.             echo "OK, Attempting to play the audio using your computer's speaker.."
  124.             AUDIOSPEAKERFORCE=1
  125.             echo "In the future, you can avoid this question by setting the environment variable"
  126.             echo "AUDIOSPEAKERFORCE to 1"
  127.             looping=0
  128.             else
  129.             echo "That is NOT one of your choices."
  130.             fi
  131.         done
  132.     fi
  133. fi
  134.  
  135. if test $playphone -eq 0
  136. then
  137.     audiohost=$thishost
  138.     if test ! -z "${DISPLAY:-}"
  139.     then
  140.         audiohost=`echo $DISPLAY | sed -e 's/:.*//'`
  141.         if test "$audiohost" = unix -o "$audiohost" = localhost
  142.         then
  143.             audiohost=$thishost
  144.         fi
  145.         if test -z "$audiohost"
  146.         then
  147.             audiohost=$thishost
  148.         fi
  149.     fi
  150.     if test ! -z "${AUDIOHOST:-}"
  151.     then
  152.         audiohost=$AUDIOHOST
  153.     fi
  154.  
  155.     if test ! "$audiohost" = "$thishost"
  156.     then
  157.         echo Sending audio to $audiohost...
  158.         if test ! -z "${MMS_AUDIO}"
  159.         then
  160.             if test $STDINPUT -eq 1
  161.             then
  162.                 cat | mms -host $audiohost "show audio/basic"
  163.             else
  164.                 cat "$@" | mms -host $audiohost "show audio/basic"
  165.             fi
  166.             exit 0
  167.         fi
  168.         thisprog=`(cd; whence showaudio)`
  169.         if test $STDINPUT -eq 1
  170.         then
  171.             cat | $RSH $audiohost $thisprog -s
  172.         else
  173.             cat "$@" | $RSH $audiohost $thisprog -s
  174.         fi
  175.         exit 0
  176.     fi
  177.  
  178.  
  179.     if test -f /usr/sbin/sfplay
  180.     then
  181.         if test $# -ne 0
  182.         then
  183.             exec /usr/sbin/sfplay -i mu-law chan 1 rate 8000 end "$@" 
  184.         else
  185.             cat > ${METAMAIL}/audio.$$
  186.             /usr/sbin/sfplay -i mu-law chan 1 rate 8000 end ${METAMAIL}/audio.$$
  187.             rm ${METAMAIL}/audio.$$
  188.             exit 0
  189.         fi
  190.     elif test -f /usr/bin/audioplay
  191.     then
  192.     # Solaris 2.0
  193.         /usr/bin/audioconvert -i raw,voice -f sun "$@" | /usr/bin/audioplay
  194.         exit $?
  195.     elif test -f /bin/audioplay
  196.     then
  197.     # Solaris 2.0
  198.         /bin/audioconvert -i raw,voice -f sun "$@" | /bin/audioplay
  199.         exit $?
  200.     elif test -d /usr/sony
  201.     then
  202.         dev=/dev/sb0
  203.     else
  204.         dev=/dev/audio
  205.     fi
  206.  
  207.     if test -w $dev
  208.     then
  209.         echo Playing audio on $thishost using $dev, one moment please...
  210.         if test $# -ne 0
  211.         then
  212.             if test ! -z "${SOX:-}"
  213.             then
  214.                 for ii in "$@"
  215.                 do
  216. #
  217. #  The "approved magic" to translate arbitary sounds
  218. #    to AU format is as follows:
  219. #
  220. #                $SOX -t auto $ii -c 1 -t aiff - | \
  221. #                $SOX -t aiff - -U -b -t au -c 1 -r 8000 $dev
  222. #
  223. #  But the following "direct" translation also seems to work
  224.                 $SOX -t auto $ii -c 1 -t au -c 1 -r 8000 $dev
  225.                 done
  226.             else
  227.                 cat "$@" > $dev
  228.             fi
  229.         else
  230.             if test ! -z "${SOX:-}"
  231.             then
  232.                 cat > ${METAMAIL}/audio.$$
  233. #
  234. #  See also above
  235. #
  236.                 $SOX -t auto ${METAMAIL}/audio.$$ -c 1 -t au -c 1 -r 8000 $dev
  237.             else
  238.                 cat > $dev
  239.             fi
  240.         fi
  241.         exit 0
  242.     fi
  243. fi
  244.  
  245. if test -d "$AUDIOBINDIR"
  246. then
  247.     thisprog=`whence showaudio`
  248.     if test -z "${AUDIOPHONE:-}"
  249.     then
  250.         if test ! -z "${MM_NOTTTY:-}"
  251.         then
  252.             if test $MM_NOTTTY -eq 1
  253.             then
  254.                 MM_NOTTTY=0; export MM_NOTTTY
  255.                 xterm -e $thisprog "$@"
  256.                 exit 0
  257.             fi
  258.         fi
  259.         echo This message contains audio, which can be sent to your telephone.
  260.         echo Please enter the telephone number at which you would like to hear this
  261.         echo-n "audio message as you would dial it from inside ${ORG}: "
  262.         read AUDIOPHONE
  263.     fi
  264.  
  265.     if test "$thishost" == "$AUDIOPHONEHOST" \
  266.         -o "$thishost" == "$AUDIOPHONEHOSTLONG"
  267.     then
  268.         echo Calling Phone number $AUDIOPHONE
  269.         echo "You MUST SAY HELLO when you answer the phone, or you will not hear the message."
  270.         mail -s "showaudio: `whoami` called $AUDIOPHONE" $AUDIOLOGMAIL < /dev/null
  271.         if test $STDINPUT -eq 1
  272.         then
  273.             cat $AUDIOBINDIR/../GREET.au "$@" - | $AUDIOBINDIR/play -\# $AUDIOPHONE -
  274.         else
  275.             cat $AUDIOBINDIR/../GREET.au "$@" | $AUDIOBINDIR/play -\# $AUDIOPHONE -
  276.         fi
  277.         echo All done
  278.         exit 0
  279.     else
  280.         echo Trying to rsh to $AUDIOPHONEHOST to send audio via telephone
  281.         if test $STDINPUT -eq 1
  282.         then
  283.             cat "$@" - | $RSH $AUDIOPHONEHOST $thisprog -p $AUDIOPHONE -
  284.         else
  285.             cat "$@" | $RSH $AUDIOPHONEHOST $thisprog -p $AUDIOPHONE -
  286.         fi
  287.         exit 0
  288.     fi
  289. fi
  290. echo ""
  291. echo "This message contains an audio mesage, which can not currently be"
  292. echo "played on this type of workstation.   If you log into an appropriate"
  293. echo "machine (currently a SPARCstation or Sony News workstation)"
  294. echo "and read this message there, you should be able to hear the audio"
  295. echo "message."
  296. echo ""
  297.  
  298. if test -z "${MM_NOTTY:-}"
  299. then
  300.     MM_NOTTY=0
  301. fi
  302. if test $MM_NOTTY -eq 1
  303. then
  304.     fname=/tmp/mm.aud.$$
  305. else
  306.     echo-n "Do you want to write the audio out to a file [y] ? "
  307.     read ANS
  308.     case "$ANS" in
  309.         [Nn]*)    exit 0 ;;
  310.     esac
  311.  
  312.     echo-n "File name:"
  313.     read fname
  314. fi
  315. cp $1 $fname
  316. if test $? -eq 0
  317. then
  318.     echo Wrote raw audio file: $fname
  319. fi
  320. exit 0
  321.